/*
 * inotify-sync - a simple file synchronizer and file system watcher
 * Copyright (C) 2010-2011, inotify-sync developers and inotify-sync contributors
 * Copyright (C) 2010-2011, Cohesion Network Security Studio
 *
 * inotify-sync is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * inotify-sync is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with inotify-sync; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/*
 * FILE:		EventHandler.h
 * USAGE:		---
 * DESCRIPTION:		---
 * OPTIONS:		---
 * REQUIREMENTS:	---
 * BUGS:		---
 * NOTES:		---
 * AUTHOR:		LI Yiwei (mail:leeyiw@gmail.com)
 * COMPANY:		---
 * VERSION:		1.0
 * CREATED:		Wed Oct  5 13:09:12 CST 2011
 * REVISION:		---
 */


#ifndef EVENTHANDLER
#define EVENTHANDLER

#include <sys/types.h>
#include <sys/wait.h>

#include "Inotify.h"
#include "Profile.h"
#include "Converter.h"

class Inotify;
struct DirNode;

struct MoveEvent
{
	uint32_t cookie;
	std::string f_path;
	std::string t_path;
};

extern Converter Conv;

#define ISDIR(mask) ((mask & IN_ISDIR)?"YES":"NO")

class EventHandler
{
public:
	EventHandler(Profile& profile);
	virtual ~EventHandler();
	
	void get_inotify(Inotify *p_inotify);
	void handle_events(std::vector<DirNode> *p_dnode_vec,
		const std::vector<inotify_event *> * const p_ievent_p_vec);
	void exec_action(std::string action,
			std::string relative_path,
			std::string fname,
			const char *is_dir,
			std::string cookie);
protected:
private:
	Profile profile;
	Inotify *p_inotify;
	std::vector<MoveEvent> mevent_vec;

	std::string watch_dir;
	std::string sync_dir;
	std::string temp_dir;
	std::string log_enable;
	std::string common_action;
	/*
	std::string create_action;
	std::string delete_action;
	std::string modify_action;
	std::string moved_from_action;
	std::string moved_to_action;
	std::string move_self_action;
	*/
	std::string custom_log;
	std::string error_log;
};

#endif
